package com.shuai.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shuai.model.po.SysOrgan;
import com.shuai.model.query.SysOrganQuery;
import com.shuai.model.vo.SysOrganVo;
import com.shuai.service.SysOrganService;
import com.shuai.utils.returnVo.ReturnModel;
import com.shuai.utils.tree.SysTreeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 机构信息 前端控制器
 *
 * @author shuai
 * @since 2022
 */
@Slf4j
@RestController
@RequestMapping("/sysOrgan")
public class SysOrganController {

    @Resource
    private SysOrganService sysOrganService;

    /**
     * 添加机构信息
     * @param sysOrgan
     * @return
     */
    @PostMapping("/addSysOrgan")
    public ReturnModel<Object> addSysOrgan(@RequestBody SysOrgan sysOrgan){
        sysOrganService.addSysOrgan(sysOrgan);
        return ReturnModel.successInstance();
    }

    /**
     * 删除机构信息
     * @param query
     * @return
     */
    @RequestMapping ("/deleteSysOrgan")
    public ReturnModel<Object> deleteSysOrgan(@RequestBody SysOrganQuery query){
        sysOrganService.deleteSysOrgan(query);
        return ReturnModel.successInstance();
    }

    /**
     * 更新机构信息
     * @param sysOrgan
     * @return
     */
    @PostMapping("/editSysOrgan")
    public ReturnModel<Object> editSysOrgan(@RequestBody SysOrgan sysOrgan){
        sysOrganService.editSysOrgan(sysOrgan);
        return ReturnModel.successInstance();
    }

    /**
     * 查询机构信息
     * @param query
     * @return
     */
    @PostMapping("/selectList")
    public ReturnModel<List<SysOrganVo>> selectList(@RequestBody SysOrganQuery query){
        List<SysOrganVo> list = sysOrganService.selectList(query);
        return ReturnModel.successInstance(list);
    }

    /**
     * 分页查询机构信息
     * @param query
     * @return
     */
    @PostMapping ("/selectPage")
    public ReturnModel<IPage<SysOrganVo>> selectPage(@RequestBody SysOrganQuery query){
        IPage<SysOrganVo> list = sysOrganService.selectPage(query);
        return ReturnModel.successInstance(list);
    }

    /**
     * 查询详细
     * @param id
     * @return
     */
    @GetMapping("/selectById")
    public ReturnModel<SysOrganVo> selectById(@RequestParam() Long id){
        SysOrganVo sysOrganVo = sysOrganService.selectById(id);
        return ReturnModel.successInstance(sysOrganVo);
    }

    /**
     * 查询机构树
     * @param query
     * @return
     */
    @PostMapping("/selectTreeTree")
    public ReturnModel<List<SysTreeVo>> selectTreeTree(@RequestBody SysOrganQuery query){
        List<SysTreeVo> treeVoList = sysOrganService.selectTreeTree(query);
        return ReturnModel.successInstance(treeVoList);
    }

    /**
     * 查询机构树列表
     * @param query
     * @return
     */
    @PostMapping("/selectTreeList")
    public ReturnModel<List<SysOrganVo>> selectTreeList(@RequestBody SysOrganQuery query){
        List<SysOrganVo> list = sysOrganService.selectTreeList(query);
        return ReturnModel.successInstance(list);
    }
}

